package DaoTest;

import com.alibaba.fastjson.JSON;
import com.zhanqiao.Utils.GetDataSourceUtil;
import com.zhanqiao.domain.MessageBean;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestDao {
    @Test
    public String  testDao() throws SQLException {
        DataSource dataSource=GetDataSourceUtil.getDataSource();
        QueryRunner queryRunner=new QueryRunner(dataSource);
        List<MessageBean> Messages = queryRunner.query("SELECT * FROM massage", new BeanListHandler<>(MessageBean.class));
//       System.out.println(Messages);

        Map hashMap = new HashMap();
        hashMap.put("code","0");
        hashMap.put("msg","");
        hashMap.put("count","1000");
        hashMap.put("data",Messages);
        String jsonString=JSON.toJSONString(hashMap);
//        System.out.println(jsonString);
        return  jsonString;


    }
}

